/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.hycreate.platform.modules.crm.project;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.hycreate.platform.common.config.Global;
import com.hycreate.platform.common.persistence.Page;
import com.hycreate.platform.common.utils.StringUtils;
import com.hycreate.platform.common.web.BaseController;

/**
 * 消息回馈Controller
 * @author hj
 * @version 2016-12-06
 */
@Controller
@RequestMapping(value = "${adminPath}/project/hycrmRemind")
public class HycrmRemindController extends BaseController {

	@Autowired
	private HycrmRemindService hycrmRemindService;
	
	@ModelAttribute
	public HycrmRemind get(@RequestParam(required=false) String id) {
		HycrmRemind entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = hycrmRemindService.get(id);
		}
		if (entity == null){
			entity = new HycrmRemind();
		}
		return entity;
	}
	
	@RequiresPermissions("project:hycrmRemind:view")
	@RequestMapping(value = {"list", ""})
	public String list(HycrmRemind hycrmRemind, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<HycrmRemind> page = hycrmRemindService.findPage(new Page<HycrmRemind>(request, response), hycrmRemind); 
		model.addAttribute("page", page);
		return "modules/project/hycrmRemindList";
	}

	@RequiresPermissions("project:hycrmRemind:view")
	@RequestMapping(value = "form")
	public String form(HycrmRemind hycrmRemind, Model model) {
		model.addAttribute("hycrmRemind", hycrmRemind);
		return "modules/project/hycrmRemindForm";
	}

	@RequiresPermissions("project:hycrmRemind:edit")
	@RequestMapping(value = "save")
	public String save(HycrmRemind hycrmRemind, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, hycrmRemind)){
			return form(hycrmRemind, model);
		}
		hycrmRemindService.save(hycrmRemind);
		addMessage(redirectAttributes, "保存插入消息成功");
		return "redirect:"+Global.getAdminPath()+"/project/hycrmRemind/?repage";
	}
	
	@RequiresPermissions("project:hycrmRemind:edit")
	@RequestMapping(value = "delete")
	public String delete(HycrmRemind hycrmRemind, RedirectAttributes redirectAttributes) {
		hycrmRemindService.delete(hycrmRemind);
		addMessage(redirectAttributes, "删除插入消息成功");
		return "redirect:"+Global.getAdminPath()+"/project/hycrmRemind/?repage";
	}

}